package view;

import java.awt.BorderLayout;
import java.awt.SystemColor;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import model.BuyTableModel;
import model.SellTableModel;
import model.FormatFactory;

import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.JXTaskPane;

import java.awt.CardLayout;

import org.jdesktop.swingx.JXSearchField;

public class SavingPanel extends JPanel {
	private static final long serialVersionUID = -3346599339031507417L;
	private JXTable table;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;
	private JPanel advanced;
	private boolean visible;

	public SavingPanel() {
		setLayout(new BorderLayout(0, 0));

		JPanel panel_2 = new JPanel();
		add(panel_2, BorderLayout.NORTH);
		panel_2.setLayout(new BorderLayout(0, 0));

		JPanel panel = new JPanel();
		panel_2.add(panel, BorderLayout.NORTH);
		panel.setBorder(new TitledBorder(null, "Tìm kiếm thông tin",
				TitledBorder.LEADING, TitledBorder.TOP, null,
				SystemColor.textHighlight));
		panel.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.PREF_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC, },
				new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, }));

		JLabel btnNewButton = new JLabel("Tìm kiếm");
		panel.add(btnNewButton, "1, 1, right, default");

		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				visible = !visible;
				advanced.setVisible(visible);
			}
		});

		JXSearchField searchField = new JXSearchField();
		searchField
				.setToolTipText("Thiết lập tìm kiếm nâng cao để tối ưu hóa tìm kiếm");
		searchField.setPrompt("Nhập thông tin cần tìm");
		searchField.setColumns(27);
		panel.add(searchField, "3, 1, fill, default");
		lblNewLabel.setIcon(new ImageIcon(getClass().getResource(
				"/images/advan.png")));
		panel.add(lblNewLabel, "5, 1");

		JButton btnNewButton_2 = new JButton("");
		btnNewButton_2.setIcon(new ImageIcon(getClass().getResource(
				"/images/search.png")));
		panel.add(btnNewButton_2, "7, 1");

		advanced = new JPanel();
		advanced.setBorder(new TitledBorder(null,
				"T\u00ECm ki\u1EBFm n\u00E2ng cao", TitledBorder.LEADING,
				TitledBorder.TOP, null, SystemColor.textHighlight));
		panel_2.add(advanced, BorderLayout.CENTER);
		advanced.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"), }, new RowSpec[] {
				FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC, }));

		JCheckBox chckbxNewCheckBox = new JCheckBox("Mã hóa đơn");
		advanced.add(chckbxNewCheckBox, "1, 1");

		textField_2 = new JTextField();
		advanced.add(textField_2, "3, 1");
		textField_2.setColumns(10);

		JCheckBox chckbxNewCheckBox_1 = new JCheckBox("Số lượng");
		advanced.add(chckbxNewCheckBox_1, "5, 1");

		textField_3 = new JTextField();
		advanced.add(textField_3, "7, 1");
		textField_3.setColumns(10);

		JCheckBox chckbxNewCheckBox_2 = new JCheckBox("Giá trị hóa đơn");
		advanced.add(chckbxNewCheckBox_2, "1, 3");

		textField_4 = new JTextField();
		advanced.add(textField_4, "3, 3");
		textField_4.setColumns(10);

		JCheckBox chckbxNewCheckBox_4 = new JCheckBox("Ngày lập");
		advanced.add(chckbxNewCheckBox_4, "5, 3");

		textField_1 = new JTextField();
		advanced.add(textField_1, "7, 3");
		textField_1.setColumns(10);

		JXTaskPane taskPane = new JXTaskPane();
		taskPane.setCollapsed(true);
		panel_2.add(taskPane, BorderLayout.SOUTH);
		taskPane.getContentPane().setLayout(new CardLayout(0, 0));

		JPanel panel_1 = new SellPanel(new SellTableModel(), null, false);
		taskPane.getContentPane().add(panel_1, "name_4177476440704");

		JPanel panel_4 = new BuyPanel(new BuyTableModel(), null, false);
		taskPane.getContentPane().add(panel_4, "name_4180451356630");

		JPanel panel_3 = new JPanel();
		add(panel_3, BorderLayout.CENTER);
		panel_3.setBorder(new TitledBorder(null,
				"Danh s\u00E1ch h\u00F3a \u0111\u01A1n", TitledBorder.LEADING,
				TitledBorder.TOP, null, SystemColor.textHighlight));
		panel_3.setLayout(new BorderLayout(0, 0));

		JScrollPane scrollPane = new JScrollPane();
		panel_3.add(scrollPane, BorderLayout.CENTER);
		scrollPane
				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		scrollPane
				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

		table = new JXTable();
		table.setModel(new DefaultTableModel(new Object[][] {
				{ null, null, null, null, "" },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null },
				{ null, null, null, null, null }, }, new String[] { "STT",
				"M\u00E3 h\u00F3a \u0111\u01A1n", "S\u1ED1 l\u01B0\u1EE3ng",
				"Ng\u00E0y l\u1EADp", "Gi\u00E1 tr\u1ECB" }));
		scrollPane.setViewportView(table);

		FormatFactory.formatHeader(table, SwingConstants.CENTER);
		FormatFactory.formatHighlighter(table, null);

		advanced.setVisible(false);
	}

	public static void main(String[] args) {
		JFrame test = new JFrame();
		test.getContentPane().add(new SavingPanel());
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		test.setVisible(true);
		test.pack();
	}
}
